package top.houry.redis.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import top.houry.redis.service.ISignService;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

@RestController
public class SignController {
    @Autowired
    private ISignService signService;

    @GetMapping("sign")
    public String sign(Long userId){
        LocalDate now = LocalDate.now().plusDays(1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
        String key = String.format("user:sign:%d:%s", userId, now.format(formatter));
        signService.sign(key, now);
        return "success";
    }

    @GetMapping("getSignInfo")
    public String getSignInfo(Long userId) {
        LocalDate now = LocalDate.now().plusDays(1);
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMM");
        String key = String.format("user:sign:%d:%s", userId, now.format(formatter));
        System.out.println(signService.getSignInfo(key));
        return "success";
    }
}
